<?php
$item_name = strlen($dcommittee['Committee']['item_name'])>2 ? $dcommittee['Committee']['item_name'] : 'Project';

function cleanstyle($text){
    return $text;
}
?>
<fieldset id="leftcolumn" class="nobullet">
    <legend>
        <?php __('List of decisions');?>
        <?php echo count($decisions)? ': '.count($decisions) : '' ?>&nbsp;&nbsp;
        <?php  
            if($A>0){
                __('Accepted');
                echo ': '.$A; 
            }
        ?>
        &nbsp;&nbsp;
        <?php 
            if ($N>0){
                __('Not accepted yet');
                echo ': '.$N;
            }
        ?>
    </legend>
    <div class="fieldset-inside">
        <?php echo $this->element('searchbox',array('from'=>$this->params['controller'].'/'.$this->params['action'])); ?>
        <?php
        if(count($decisions)){
            echo "<br />";
            $no=0;
            
            foreach($decisions as $decision){
				$no++;
				echo "<table>
						<tr>
							<td><strong>".$no."</strong></td><td>";
                if ($allow[$decision['Decision']['id']]==0){
                    echo '<div>';
                }else{
                    if ($noupdated[$decision['Decision']['id']]==0){
                        echo '<div class="updated">';
                    }
                    else{
                        echo '<div class="noupdated">';
                    }
                }
       
        ?>
                <ul>
                    <li>
                        <?php
                            $singular=strtolower(Inflector::singularize($this->params['controller']));
                            if($secretariat[$decision['Meeting']['id']] ||$auth_user['User']['superuser']){
                                echo $html->link($html->image('icons/edit.gif',array('title'=>__('Edit',true),'alt'=>__('Edit',true))),array('committee'=>$dcommittee['Committee']['short_name'],'controller'=>'decisions','action'=>'edit',$singular.'id'=>$decision['Decision'][$singular.'_id'],'id'=>$decision['Decision']['id']),array('escape'=>false));
                                echo $html->link($html->image('icons/delete.gif',array('title'=>__('Delete',true),'alt'=>__('Delete',true))),array('committee'=>$dcommittee['Committee']['short_name'],'controller'=>'decisions','action'=>'delete',$singular.'id'=>$decision['Decision'][$singular.'_id'],'id'=>$decision['Decision']['id']),array('escape'=>false),__('Deleting a decision will remove all data related to it.',true).'\n'.__('Are you sure you want to delete this decision?',true));
                                //echo $html->link($html->image('icons/go-up.gif',array('title'=>__('Move up',true),'alt'=>__('Move up',true))),array('committee'=>$dcommittee['Committee']['short_name'],'controller'=>'decisions','action'=>'promote',$singular.'id'=>$decision['Decision'][$singular.'_id'],'id'=>$decision['Decision']['id']),array('escape'=>false));
                                //echo $html->link($html->image('icons/go-down.gif',array('title'=>__('Move down',true),'alt'=>__('Move down',true))),array('committee'=>$dcommittee['Committee']['short_name'],'controller'=>'decisions','action'=>'demote',$singular.'id'=>$decision['Decision'][$singular.'_id'],'id'=>$decision['Decision']['id']),array('escape'=>false));
                                echo $html->link($html->image('icons/email.gif',array('title'=>__('Ask for status update',true),'alt'=>__('Ask for status update',true))),array('committee'=>$dcommittee['Committee']['short_name'],'controller'=>'decisions','action'=>'announcedecision',$singular.'id'=>$decision['Decision'][$singular.'_id'],'id'=>$decision['Decision']['id']),array('escape'=>false));
                            }else{
                                if(!empty($permiss[$decision['Decision']['id']]['Edit'])){
                                    echo $html->link($html->image('icons/edit.gif',array('title'=>__('Edit',true),'alt'=>__('Edit',true))),array('committee'=>$dcommittee['Committee']['short_name'],'controller'=>'decisions','action'=>'edit',$singular.'id'=>$decision['Decision'][$singular.'_id'],'id'=>$decision['Decision']['id']),array('escape'=>false));
                                }
                                if(!empty($permiss[$decision['Decision']['id']]['Delete'])){
                                    echo $html->link($html->image('icons/delete.gif',array('title'=>__('Delete',true),'alt'=>__('Delete',true))),array('committee'=>$dcommittee['Committee']['short_name'],'controller'=>'decisions','action'=>'delete',$singular.'id'=>$decision['Decision'][$singular.'_id'],'id'=>$decision['Decision']['id']),array('escape'=>false),__('Deleting a decision will remove all data related to it.',true).'\n'.__('Are you sure you want to delete this decision?',true));
                                }
                            }
                        ?>  
                    </li>
                    <?php if ($decision['Decision']['approved']==1 && (strtolower($this->params['controller']) == 'items' || (strtolower($this->params['controller']) == 'meetings' && $decision['Item']['deadline']=='0000-00-00'))){?>
                        <li>
                            <?php echo '<div style="float:right">'.$html->image('icons/inminutes.gif',array('title'=>__('In minutes',true))).'</div>';?>
                        </li>
                    <?php }elseif(($secretariat[$meeting['Meeting']['id']]) && $decision['Decision']['approved']==0 && (empty($needcheck))){ ?>
						<li>
                            <?php echo '<div style="float:right">['.$ajax->link(__('Add decision to minutes',true), array('committee'=>$dcommittee['Committee']['short_name'],'controller'=>'decisions','action'=>'approvedecision','id'=>$decision['Decision']['id']),array('complete'=>'location.reload()','escape'=>false),sprintf(__('This will put the decision in the minutes for the chairperson to approve. Proceed?', true))).']</div>';?>
                        </li>
                    <?php } ?>
                    <li>
                        <span class="viewtitle">
                            <?php if (strtolower($this->params['controller']) == 'meetings'):?>
                                <?php echo ucwords($item_name);?>:</span>
                                <?php echo $html->link($decision['Item']['name'],array('committee'=>$dcommittee['Committee']['short_name'],'controller'=>'items','action'=>'view',$decision['Item']['id']));?>
                            <?php elseif (strtolower($this->params['controller']) == 'items'):?>
                                <?php __('Meeting');?>:</span>
                                <?php echo $html->link($decision['Meeting']['meeting_num'],array('committee'=>$dcommittee['Committee']['short_name'],'controller'=>'meetings','action'=>'view',$decision['Meeting']['id']));?>
                            <?php endif;?>
                        <?php if ($decision['Decision']['approved']==1 && !(strtolower($this->params['controller']) == 'items' || (strtolower($this->params['controller']) == 'meetings' && $decision['Item']['deadline']=='0000-00-00'))){
                            echo '<div style="float:right">'.$html->image('icons/inminutes.gif',array('title'=>__('In minutes',true))).'</div>'; 
                        }?>
                    </li>
                    <?php if ($decision['Decision']['deadline']!='0000-00-00'):?>
                        <li>
                            <span class="viewtitle"><?php __('Decision Deadline');?>: </span>
                            <?php echo date(Configure::read('date_format'),strtotime($decision['Decision']['deadline']));?>
                        </li>
                    <?php endif; ?>
                    <li><span class="viewtitle"><?php __('Description');?>: </span><?php echo $html->div('decision_text',cleanstyle($decision['Decision']['description']));?></li>
                    <?php if(isset($decision['MultiFile']['additionalfiles'])){ ?>
                        <li><span class="viewtitle"><?php __('Additional Files');?>: </span><?php echo $this->element('multifile',array('multifiles'=>$decision['MultiFile']['additionalfiles']));?></li>
                    <?php } ?>
                    <?php if(count($decision['User'])):?>
                        <li><span class="viewtitle"><?php __('Individual Implementor');?>: </span>
                            <?php 
                                echo "<ul>"; 
                                    foreach($decision['User'] as $user)  echo "<li>".$user['name']."</li>";
                                echo "</ul>"; 
                            ?> 
                        </li>
                    <?php endif;?>
                    <?php if(count($decision['Group'])):?>
                        <li><span class="viewtitle"><?php __('Group Implementor');?>: </span>
                            <?php
                                echo "<ul>"; 
                                    foreach($decision['Group'] as $user) echo "<li>".$user['name']."</li>"; 
                                echo "</ul>"; 
                            ?> 
                        </li>
                    <?php endif;?>
                    <li>
                        <?php 
                            echo __('Comments',true).': ';
                            if( ($auth_user['User']['superuser'] ||$secretariat[$decision['Meeting']['id']]) || ($permiss[$decision['Decision']['id']]['View'])){
                                echo $html->link($comment->no_of_comments('Decision',$decision),array(
                                    'controller'=>'decisions',
                                    'action'=>'view',
                                    'committee'=>$dcommittee['Committee']['short_name'],
                                    $decision['Decision']['id']."#comments"
                                ));
                            } else { 
                                echo $comment->no_of_comments('Decision',$decision); 
                            }
                            echo ' | ';
                            $to_echo_status = count($decision['Groupstatus'])||count($decision['Userstatus'])||count($decision['Decision']['status']) ? __("Updated",true) : __("No update",true);
                            echo __('Status',true).': ';
                            if( ($auth_user['User']['superuser'] ||$secretariat[$decision['Meeting']['id']]) || $permiss[$decision['Decision']['id']]['View']){
                                echo $html->link($to_echo_status,array(
                                    'controller'=>'decisions',
                                    'action'=>'view',
                                    'committee'=>$dcommittee['Committee']['short_name'],
                                    $decision['Decision']['id']."#status"
                                ));
                            } else {
                                echo __($to_echo_status,array(
                                    'controller'=>'decisions',
                                    'action'=>'view',
                                    'committee'=>$dcommittee['Committee']['short_name'],
                                    $decision['Decision']['id']."#status"
                                ));
                            }
                            if(date(Configure::read('date_format'),strtotime($decision['Decision']['status_deadline']))>'01/01/1970'){
                                echo ' | ';
                                echo __('Update status deadline',true).':';
                                echo date(Configure::read('date_format'),strtotime($decision['Decision']['status_deadline']));
                            }
                        ?>
                    </li>
                </ul>
                </div> 
                </td><td>
					</tr>
				</table>
                <hr/>
        <?php 
            }
        }else { 
            __('No decisions found'); 
        }
        ?>
    </div>
</fieldset>
